<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>保存诗词</title>
    <link rel="stylesheet" href="/css/common.css" type="text/css">
    <script src="/js/jquery/jquery-3.4.1.js"></script>
    <script src="/js/service/common.js"></script>
    <script>
        defaultBackPage();
        function save() {
            let preface = $("#preface").val();
            preface = preface ? preface.trim() : '';
            preface = '' === preface ? null : preface;
            $.ajax({
                url: "/poetry/savePoetry",
                type: "POST",
                dataType: "json",
                contentType: 'application/json',
                data: JSON.stringify({
                    title: $("#title").val(),
                    authorId:  $("#author").val(),
                    text: $("#text").val(),
                    position: $("#position").val(),
                    type: $("#type").val(),
                    preface: preface,
                    [[${res.idParam}]]
                }),
                success: function (json) {
                    if(json.code === 200){
                        alert("保存成功！！！");
                        window.location.href="/page/service/poetry/poetryList";
                    }else{
                        tipsMessage(json);
                    }
                },
                error: function () {
                    alert("提交失败");
                }
            });
        }
    </script>
</head>
<body>
    <object class="object-top" data="/page/common/top"></object>
    <div class="center-div">
    <h1>保存诗词</h1>
    <form id="form" style="margin-top: 4%">
        <label>标题</label>
        <label>
            <input style="width: 19.4%" placeholder="请输入标题" name="title" type="text" id="title" th:value="${res.poetry.title}"/>
        </label><br>
        <label>&nbsp;&nbsp;序&nbsp;&nbsp;</label>
        <label>
            <textarea style="width: 19.6%" placeholder="请输入序" rows="3" name="text" type="text" id="preface" th:text="${res.poetry.preface}"></textarea>
        </label><br>
        <label>内容</label>
        <label>
            <textarea style="width: 19.6%" placeholder="请输入内容" rows="6" name="text" type="text" id="text" th:text="${res.poetry.content}"></textarea>
        </label><br>
        <label>作者</label>
        <label>
            <select id="author" style="width: 20%">
                <option value="0">---请选择---</option>
                <option th:each="author, iterStat:${res.authorList}" th:value="${author.id}" th:text="${author.author}" th:selected="${author.id} == ${res.poetry.authorId}"></option>
            </select>
        </label><br>
        <label>类型</label>
        <label>
            <select id="type" style="width: 20%">
                <option value="0">---请选择---</option>
                <option th:each="type, iterStat:${res.codes}" th:value="${type.code}" th:text="${type.value}" th:selected="${type.code} == ${res.poetry.type}"></option>
            </select>
        </label><br>
        <label>断句</label>
        <label>
            <input style="width: 19.4%" placeholder="请输入断句点" name="position" type="text" id="position" th:value="${res.poetry.position}"/>
        </label><br>
        <label><input type="button" class="btn" value="确定" onclick="save()"></label>
        <label><input type="reset" class="btn" value="重置"></label>
    </form>
</div>
</body>
</html>